﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
                    >

   

    <PathGeometry x:Key="TreeArrow" Figures="M0,0 L0,6 L6,0 z"/>
    
    <Style x:Key="TreeViewExpandCollapseToggleStyle" TargetType="{x:Type ToggleButton}">
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="Width" Value="18"/>
        <Setter Property="Height" Value="18"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToggleButton}">
                    <Grid>
                        <Image x:Name="img" Stretch="None" Opacity="0.6" Source="/MishraReader;component/Assets/Light/Expand.png" />
                    </Grid>
                    
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Opacity" TargetName="img" Value="1"/>
                        </Trigger>
                        <Trigger Property="IsChecked" Value="True">
                            <Setter Property="Source" TargetName="img" Value="/MishraReader;component/Assets/Light/Collapse.png"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="FeedTreeView" TargetType="{x:Type TreeView}">
        <Setter Property="Foreground" Value="{DynamicResource MetroText}"/>
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/>
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TreeView}">
                    <ScrollViewer x:Name="_tv_scrollviewer_" Background="{TemplateBinding Background}" 
                                  CanContentScroll="false" 
                                  Focusable="false" 
                                  HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}" 
                                  Padding="{TemplateBinding Padding}" 
                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                                  VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}" 
                                  Style="{DynamicResource ScrollViewerWithOuterScrollbar}">
                        <ItemsPresenter/>
                    </ScrollViewer>
                    <ControlTemplate.Triggers>
                        <Trigger Property="VirtualizingStackPanel.IsVirtualizing" Value="true">
                            <Setter Property="CanContentScroll" TargetName="_tv_scrollviewer_" Value="true"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="FeedsTreeViewItemStyle" TargetType="{x:Type TreeViewItem}">
        <Style.Resources></Style.Resources>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="HorizontalAlignment" Value="Stretch"/>
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        <Setter Property="VerticalContentAlignment" Value="Stretch"/>
        <Setter Property="Padding" Value="0,0,0,0"/>
        <Setter Property="FontSize" Value="{StaticResource NormalTextSize}"/>
        <Setter Property="FontFamily" Value="{DynamicResource DefaultFont}"/>
        <Setter Property="Foreground" Value="{DynamicResource MetroTextLight}"/>
        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TreeViewItem}">
                    <Grid Margin="0,0,0,2" x:Name="grid">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition MinWidth="19" Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <Border x:Name="Bd" Grid.ColumnSpan="3"  Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
                            <StackPanel Orientation="Horizontal">
                                <ToggleButton HorizontalAlignment="Left" 
                                              Margin="4" 
                                              VerticalAlignment="Center" 
                                              x:Name="Expander" 
                                              ClickMode="Press" 
                                              IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}" 
                                              Style="{StaticResource TreeViewExpandCollapseToggleStyle}"/>      
                                <ContentPresenter x:Name="PART_Header" 
                                                  ContentSource="Header" 
                                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                            </StackPanel>
                        </Border>
                        <ItemsPresenter x:Name="ItemsHost" Grid.ColumnSpan="3" Grid.Column="0" Grid.Row="1"/>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsExpanded" Value="false">
                            <Setter Property="Visibility" TargetName="ItemsHost" Value="Collapsed"/>
                        </Trigger>
                        <Trigger Property="HasItems" Value="false">
                            <Setter Property="Visibility" TargetName="Expander" Value="Hidden"/>
                        </Trigger>
                       <!-- <Trigger Property="IsMouseOver" Value="true">
                           
                        </Trigger>-->
                       <!-- <Trigger Property="IsSelected" Value="true">
                            <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
                            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
                        </Trigger>-->
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                        </Trigger>
                        <Trigger Property="IsSelected" Value="true">
                            <Setter Property="Foreground" Value="{DynamicResource MetroAccentBrush}"/>
                        </Trigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsSelected" Value="False" />
                                <Condition Property="IsMouseOver" Value="True" />
                            </MultiTrigger.Conditions>
                            <Setter Property="Opacity" TargetName="grid" Value="0.5"/>
                        </MultiTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        
        <Style.Triggers>
            <Trigger Property="VirtualizingStackPanel.IsVirtualizing" Value="true">
                <Setter Property="ItemsPanel">
                    <Setter.Value>
                        <ItemsPanelTemplate>
                            <VirtualizingStackPanel/>
                        </ItemsPanelTemplate>
                    </Setter.Value>
                </Setter>
            </Trigger>
        </Style.Triggers>
    </Style>
    
    <Style x:Key="CategoriesTreeViewItemStyle" TargetType="{x:Type TreeViewItem}" BasedOn="{StaticResource FeedsTreeViewItemStyle}">
        <Setter Property="Background" Value="{DynamicResource MetroAccentBrush}"/>
        <Setter Property="Padding" Value="2,3"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TreeViewItem}">
                    <Grid Margin="0,0,0,2">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        
                        <Grid>
                            <Rectangle x:Name="border"  Fill="{DynamicResource MetroAccentBrush}" />   
                            <Rectangle x:Name="MouseOverElement" Fill="#3FFFFFFF" Opacity="0" />
                            <Border x:Name="Bd"  Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
                                <StackPanel Orientation="Horizontal">
                                    <ToggleButton HorizontalAlignment="Left" 
                                              Margin="0,4,0,4" 
                                              VerticalAlignment="Center" 
                                              x:Name="Expander" 
                                              ClickMode="Press" 
                                              IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}" 
                                              Style="{StaticResource TreeViewExpandCollapseToggleStyle}"/>
                                   

                                        <ContentPresenter x:Name="PART_Header" 
                                                          Margin="2,0,0,0"
                                                  ContentSource="Header" 
                                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>

                                </StackPanel>
                            </Border>
                            <Grid x:Name="CheckMark" Opacity="0" IsHitTestVisible="False">
                                <Rectangle Fill="#33000000" Stroke="Black" StrokeThickness="1" />
                                <Path Data="M0,0 L10,0 10,10 z" Fill="Black" HorizontalAlignment="Right" Height="10" Stretch="Fill" VerticalAlignment="Top" Width="10" />
                            </Grid>
                        </Grid>
                        
                        <ItemsPresenter x:Name="ItemsHost" Grid.Row="1"/>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualStateGroup.Transitions>
                                    <VisualTransition GeneratedDuration="0:0:0.2"/>
                                </VisualStateGroup.Transitions>
                                <VisualState x:Name="Normal"/>
                                <VisualState x:Name="MouseOver">
                                    <Storyboard>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="MouseOverElement">
                                            <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
                                        </DoubleAnimationUsingKeyFrames>

                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Pressed">
                                    <Storyboard>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="content">
                                            <EasingDoubleKeyFrame KeyTime="0" Value="0.8"/>
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="content">
                                            <EasingDoubleKeyFrame KeyTime="0" Value="0.2"/>
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="SelectionStates">
                                <VisualStateGroup.Transitions>
                                    <VisualTransition GeneratedDuration="0:0:0.2"/>
                                </VisualStateGroup.Transitions>
                                <VisualState x:Name="Selected">
                                    <Storyboard>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="CheckMark">
                                            <EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="0.5"/>
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Unselected">
                                    <Storyboard>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="CheckMark">
                                            <EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="0.0"/>
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                    </Grid>
                    
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsExpanded" Value="false">
                            <Setter Property="Visibility" TargetName="ItemsHost" Value="Collapsed"/>
                        </Trigger>
                        <Trigger Property="HasItems" Value="false">
                            <Setter Property="Visibility" TargetName="Expander" Value="Collapsed"/>
                        </Trigger>
                        <DataTrigger Binding="{Binding IsFeed}" Value="true">
                            <Setter Property="Visibility" TargetName="Expander" Value="Collapsed" />
                        </DataTrigger>
                        <!-- <Trigger Property="IsMouseOver" Value="true">
                           
                        </Trigger>-->
                        <!-- <Trigger Property="IsSelected" Value="true">
                            <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
                            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
                        </Trigger>-->
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="HorizontalContentAlignment" Value="Left"/>
        <Setter Property="Margin" Value="0,0,0,3"/>
        <Setter Property="Foreground" Value="{DynamicResource MetroHeadingColorLight}"/>
        <Setter Property="FontSize" Value="{DynamicResource LargeTextSize}"/>
        <Setter Property="FontFamily" Value="{DynamicResource LightFont}"/>
    </Style>
</ResourceDictionary>